package org.budo.support.spring.io.util;

import java.io.FileInputStream;
import java.io.InputStream;

import org.budo.support.lang.util.FileUtil;
import org.springframework.core.io.ClassPathResource;

/**
 * @author lmw
 * 
 * @deprecated use ResourceUtil
 * @see org.budo.support.spring.io.util.ResourceUtil
 */
@Deprecated
public class ClassPathResourceUtil {
    public static InputStream classPathRead(Class<?> type, String fileName) {
        try {
            return new ClassPathResource(fileName).getInputStream();
        } catch (Exception e1) {
            try {
                String currentPath = FileUtil.getCodeSourceLocation(type);
                return new FileInputStream(currentPath + fileName);
            } catch (Exception e2) {
                try {
                    String currentPath = FileUtil.getCodeSourceLocation(type);
                    String filePath = currentPath.replace("/lib/", "/") + fileName;
                    return new FileInputStream(filePath); // 权宜之计, 获取的路径是 support.jar 的位置 , 期望得到的是 account-service.jar的位置
                } catch (Exception e3) {
                    throw new RuntimeException(e1.getMessage() + ", " + e2.getMessage() + ", " + e3.getMessage(), e1);
                }
            }
        }
    }
}